﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RXY_Mall.Core.Tool
{
    /// <summary>
    /// 随机数帮助类
    /// </summary>
    public class RandomHelper
    {
        /// <summary>
        /// 创建随机值
        /// </summary>
        /// <param name="length">长度</param>
        /// <param name="onlyNumber">是否只包含数字</param>
        /// <returns>随机值</returns>
        public static string CreateRandomValue(int length)
        {
            Random _random = new Random();
            int index;
            StringBuilder randomValue = new StringBuilder();

            for (int i = 0; i < length; i++)
            {
                index = _random.Next(0, 9);

                randomValue.Append(index);
            }

            return randomValue.ToString();
        }

        /// <summary>
        /// 创建随机对
        /// </summary>
        /// <param name="length">长度</param>
        /// <param name="onlyNumber">是否只包含数字</param>
        /// <param name="randomKey">随机键</param>
        /// <param name="randomValue">随机值</param>
        public static void CreateRandomPair(int length, out string randomKey, out string randomValue)
        {
            Random _random = new Random();
            StringBuilder randomKeySB = new StringBuilder();
            StringBuilder randomValueSB = new StringBuilder();

            int index1;
            int index2;
            for (int i = 0; i < length; i++)
            {

                index1 = _random.Next(0, 10);
                index2 = _random.Next(0, 10);

                randomKeySB.Append(index1);
                randomValueSB.Append(index2);
            }
            randomKey = randomKeySB.ToString();
            randomValue = randomValueSB.ToString();
        }

    }
}
